<p>
A Nuntium Application simply represents your application.<br/>
If you have many applications you would create many Nuntium Applications, and you can choose to interface with each of them in a different way.
</p>

<% unless logged_in_application %>
  <p><%= link_to 'Create new Application', new_application_path -%></p>
<% end %>

<%- unless applications.empty? -%>
  <table class="table" cellspacing="4">
    <tr>
      <th>Name</th>
      <th>Interface</th>
      <th>Route via last channel?</th>
      <th>Strategy</th>
      <th>Delivery ACK</th>
      <th></th>
    </tr>
    <%- applications.each_with_index do |app, i| -%>
      <tr class="<%= i.even_to_s -%>">
        <td><%= app.name -%></td>
        <td><%= app.interface_description -%></td>
        <td><%= app.use_address_source? ? 'Yes' : 'No' -%></td>
        <td><%= app.strategy_description -%></td>
        <td><%= app.delivery_ack_method_description -%></td>
        <td>
          <%= link_to "view log", logs_path(:search => "application:#{app.name}") -%>
          <%= link_to "view aos", ao_messages_path(:search => "application:#{app.name}") -%>
          <%= link_to "view ats", at_messages_path(:search => "application:#{app.name}") -%>
          <%= link_to "edit", edit_application_path(app) -%>
          <%= link_to "delete", app, :method => :delete, :confirm => "Are you sure you want to delete the application #{app.name}?" unless logged_in_application -%>
        </td>
      </tr>
    <%- end -%>
  </table>
<%- end -%>

<h5>Application Routing Rules</h5>
  <% unless logged_in_application %>
    <%-
    applications_names = applications.map(&:name).sort!
    if applications_names.length < 2
      -%>
      <p>
      No need to specify these rules right now since you don't have more than one application.
      </p>
      <%-
    else
      if app_routing_rules.blank?
        -%>
        <p id="errorNotice">
        Now that you have more than one application you should configure rules
        to determine the application an AT message is routed to.
        </p>
        <%-
      end
      -%>
      <%= form_for account, :url => routing_rules_applications_path do |f| -%>
        <%= f.error_messages -%>
        <p>
        Specify here rules to route AT messages to specific applications.<br/>
        These rules will not be executed if an AT message is received via a channel that belongs to an application<br/>
        or when a message specifies the custom attribute "application".
        <a href="http://code.google.com/p/nuntium/wiki/Rules" target="_blank">Learn more...</a>
        </p>

        <p>
        <b>Here you can only determine the target application. To change an AT message's attributes specify
        AT rules for each application.</b>
        </p>

        <div class="apprules"></div>

        <script type="text/javascript">
        var applications = <%= applications_names.to_json.html_safe -%>;
        jQuery(function(){
            init_rules(jQuery('.apprules'), 'apprules', <%= app_routing_rules.to_json.html_safe -%>, null, {include: ['application']});
        });
        </script>

        <%= submit_tag 'Update rules' -%>
      <%- end -%>
    <%- end -%>
  <%- end -%>

  <p>
    Routing can also be manipulated setting <%= link_to 'custom attributes', custom_attributes_path %> to specific users.
  </p>
